/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rcnss.ui.form.field.factory;

import com.rcnss.ui.form.EditForm;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;
import com.vaadin.data.Item;
import com.vaadin.data.validator.StringLengthValidator;
import com.vaadin.ui.Component;
import com.vaadin.ui.TextField;

/**
 *
 * @author Guesmi
 */
public class SubscribeFieldFactory extends DefaultFieldFactory {
    @Override
    public Field createField(Item item, Object propertyId,
                Component uiContext) {
        Field f = super.createField(item, propertyId, uiContext);
        if("Name".equals(propertyId))
        {
            TextField tf = (TextField)f;
            tf.setRequired(true);
            tf.setWidth(EditForm.COMMON_FIELD_WIDTH);
            tf.setRequiredError("Nom Obligatoire");
            tf.addValidator(new StringLengthValidator("Last Name must be 3-50 characters",
                    3, 30, false));
        } else if ("Mat".equals(propertyId))
        {
            TextField tf = (TextField)f;
            tf.setRequired(true);
            tf.setWidth(EditForm.COMMON_FIELD_WIDTH);
            tf.setRequiredError("Matricule Obligatoire");
            tf.addValidator(new StringLengthValidator("Last Name must be 3-50 characters",
                    3, 30, false));
        } else if("Message".equals(propertyId))
        {
            TextField tf = (TextField)f;
            tf.setColumns(20);
            tf.setRows(10);
        }

        return f;
    }

}
